package com.tangmu.rabbits.adapter.home;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.tangmu.rabbits.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/5/3.
 */

public class BrandIflashbuyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private LayoutInflater inflater;
    private List<Integer> datas = new ArrayList<>();

    public BrandIflashbuyAdapter(Context mContext, List<Integer> datas) {
        this.mContext = mContext;
        this.datas = datas;
        inflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new BrandIflashViewHolder(inflater.inflate(R.layout.rv_item_brand_iflash_layout, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        BrandIflashViewHolder viewHolder = (BrandIflashViewHolder) holder;

        viewHolder.itemRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, OrientationHelper.VERTICAL));
        viewHolder.itemRecyclerView.setNestedScrollingEnabled(false);
        viewHolder.itemRecyclerView.setFocusableInTouchMode(false);
        viewHolder.itemRecyclerView.requestFocus();
        viewHolder.itemAdapter = new BrandIflashbuyItemAdapter(mContext, datas);
        viewHolder.itemRecyclerView.setAdapter(viewHolder.itemAdapter);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class BrandIflashViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_brand_img)
        ImageView ivBrandImg;
        @BindView(R.id.item_recyclerView)
        RecyclerView itemRecyclerView;
        private BrandIflashbuyItemAdapter itemAdapter;

        public BrandIflashViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
